<template>
<div>
<div style="width:96%;margin:auto;">
<mt-field placeholder="收货人" v-model="address.username" style="margin-top:-20px;"></mt-field>
<mt-field placeholder="邮编" v-model="address.postcode"></mt-field>
<mt-field placeholder="省市区" v-model="address.area"></mt-field>
<mt-field placeholder="详细地址" v-model="address.location"></mt-field>
<mt-button type="primary" size="large" style="margin-top:20px" v-on:click="addressClick">保存</mt-button>
</div>
</div>
</template>

<script>
import { Toast } from 'mint-ui';
export default {
  data() {
    return {
        address:{},
        addressarr:[]
    }
  },methods: {
      addressClick(){
          if(!this.address.username){
              Toast('请填写收货人');
          }else if(!this.address.postcode){
              Toast('请填写邮编');
          }else if(!this.address.area){
              Toast('请填写省市区');
          }else if(!this.address.location){
              Toast('请填写详细地址');
          }else{
             if("addressarr" in localStorage){
             this.addressarr=JSON.parse(localStorage.addressarr)
             this.addressarr.push(this.address)
             localStorage.addressarr=JSON.stringify(this.addressarr)
             }else{
             this.addressarr.push(this.address)
             localStorage.addressarr=JSON.stringify(this.addressarr)
             }
            Toast('添加成功');
            this.address={}
      }
  }
}}
</script>

<style scoped>
</style>